/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frm_actualizar.java
 *
 * Created on 4/06/2011, 11:37:07 PM
 */
package CapaPresentacion;

import CapaControl.ControlDatos;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author langeblanc
 */
public class frm_actualizar extends javax.swing.JFrame {

    /** Creates new form frm_actualizar */
    public frm_actualizar() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        marengoPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("marengoPU").createEntityManager();
        parametrosQuery = java.beans.Beans.isDesignTime() ? null : marengoPUEntityManager.createQuery("SELECT p FROM Parametros p");
        parametrosList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : parametrosQuery.getResultList();
        btn_regresar = new javax.swing.JButton();
        tpnl_opciones = new javax.swing.JTabbedPane();
        pnl_ccontrasena = new javax.swing.JPanel();
        btn_ccontrasena = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        lbl_new_pwd = new javax.swing.JLabel();
        pf_contrasena = new javax.swing.JPasswordField();
        lbl_confirm = new javax.swing.JLabel();
        pf_conf_contrasena = new javax.swing.JPasswordField();
        pnl_cparam = new javax.swing.JPanel();
        lbl_identificador = new javax.swing.JLabel();
        lbl_nivel = new javax.swing.JLabel();
        lbl_cau_ent = new javax.swing.JLabel();
        lbl_cau_sal = new javax.swing.JLabel();
        tf_indentificador = new javax.swing.JTextField();
        tf_nivel_tanque = new javax.swing.JTextField();
        tf_caudal_ent = new javax.swing.JTextField();
        tf_caudal_salida = new javax.swing.JTextField();
        lbl_pH = new javax.swing.JLabel();
        tf_pH = new javax.swing.JTextField();
        btn_actualizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("FORMULARIO DE ACTUALIZACIÓN DE DATOS");
        setLocationByPlatform(true);
        setName("frm_update"); // NOI18N

        btn_regresar.setText("Regresar");
        btn_regresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_regresarActionPerformed(evt);
            }
        });

        tpnl_opciones.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);

        pnl_ccontrasena.setAutoscrolls(true);

        btn_ccontrasena.setText("Cambiar Contraseña");
        btn_ccontrasena.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ccontrasenaActionPerformed(evt);
            }
        });

        lbl_new_pwd.setText("Nueva contraseña");

        lbl_confirm.setText("Confirmar nueva contraseña");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(lbl_new_pwd))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(lbl_confirm)))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pf_conf_contrasena)
                    .addComponent(pf_contrasena, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pf_contrasena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_new_pwd))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(pf_conf_contrasena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(lbl_confirm, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnl_ccontrasenaLayout = new javax.swing.GroupLayout(pnl_ccontrasena);
        pnl_ccontrasena.setLayout(pnl_ccontrasenaLayout);
        pnl_ccontrasenaLayout.setHorizontalGroup(
            pnl_ccontrasenaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnl_ccontrasenaLayout.createSequentialGroup()
                .addContainerGap(102, Short.MAX_VALUE)
                .addGroup(pnl_ccontrasenaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnl_ccontrasenaLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(77, 77, 77))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnl_ccontrasenaLayout.createSequentialGroup()
                        .addComponent(btn_ccontrasena)
                        .addGap(179, 179, 179))))
        );
        pnl_ccontrasenaLayout.setVerticalGroup(
            pnl_ccontrasenaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnl_ccontrasenaLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_ccontrasena)
                .addContainerGap(135, Short.MAX_VALUE))
        );

        tpnl_opciones.addTab("Cambiar Contraseña", pnl_ccontrasena);

        lbl_identificador.setText("Identificador de parámetro");

        lbl_nivel.setText("nivel del tanque (m2)");

        lbl_cau_ent.setText("caudal de entrada (lt/día)");

        lbl_cau_sal.setText("caudal de salida (lt/día)");

        lbl_pH.setText("pH (máximo)");

        btn_actualizar.setText("Actualizar parámetros");
        btn_actualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_actualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnl_cparamLayout = new javax.swing.GroupLayout(pnl_cparam);
        pnl_cparam.setLayout(pnl_cparamLayout);
        pnl_cparamLayout.setHorizontalGroup(
            pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnl_cparamLayout.createSequentialGroup()
                .addGap(104, 104, 104)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl_pH)
                    .addComponent(lbl_cau_sal)
                    .addComponent(lbl_cau_ent)
                    .addComponent(lbl_nivel)
                    .addComponent(lbl_identificador))
                .addGap(41, 41, 41)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tf_pH)
                    .addComponent(tf_nivel_tanque, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tf_caudal_ent, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tf_indentificador, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tf_caudal_salida, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btn_actualizar)
                .addContainerGap(14, Short.MAX_VALUE))
        );
        pnl_cparamLayout.setVerticalGroup(
            pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnl_cparamLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_identificador)
                    .addComponent(tf_indentificador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl_nivel)
                    .addComponent(tf_nivel_tanque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_cau_ent)
                    .addComponent(tf_caudal_ent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_cau_sal)
                    .addComponent(tf_caudal_salida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(pnl_cparamLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_pH)
                    .addComponent(tf_pH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(50, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnl_cparamLayout.createSequentialGroup()
                .addContainerGap(136, Short.MAX_VALUE)
                .addComponent(btn_actualizar)
                .addGap(133, 133, 133))
        );

        tpnl_opciones.addTab("Actualizar parámetros de la planta de tratamiento", pnl_cparam);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(229, 229, 229)
                        .addComponent(btn_regresar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tpnl_opciones, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tpnl_opciones, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btn_regresar)
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_regresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_regresarActionPerformed
        // TODO add your handling code here:
        frm_panel_control_admin pc = new frm_panel_control_admin();
        pc.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btn_regresarActionPerformed

    private void btn_ccontrasenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ccontrasenaActionPerformed
        String pwd, cpwd;
        pwd = pf_contrasena.getText();
        cpwd = pf_conf_contrasena.getText();
        if (pwd.equals(cpwd)) {
            ControlDatos cd = new ControlDatos();
            cd.ActualizaContrasena("admin", pwd);
             JOptionPane.showMessageDialog(null, "Se ha cambiado la contraseña correctamente");
        } else {
            JOptionPane.showMessageDialog(null, "Las contraseñas no coinciden. Intente de nuevo");
        }
    }//GEN-LAST:event_btn_ccontrasenaActionPerformed

    private void btn_actualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_actualizarActionPerformed
        // TODO add your handling code here:
        ControlDatos cd = new ControlDatos();
        if (
        cd.ActualizasParametros(Integer.parseInt(tf_indentificador.getText()),
                Double.parseDouble(tf_nivel_tanque.getText()), Double.parseDouble(tf_caudal_ent.getText()),
                Double.parseDouble(tf_caudal_salida.getText()), Double.parseDouble(tf_pH.getText()))) {
             JOptionPane.showMessageDialog(null, "Se han actualizado los parámetros con éxito");
        } else {
        JOptionPane.showMessageDialog(null, "Hubo un error desconocido");
        }
    }//GEN-LAST:event_btn_actualizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(laf.getName())) {
                try {
                    UIManager.setLookAndFeel(laf.getClassName());
                } catch (Exception ex) {
                }
            }
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frm_actualizar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_actualizar;
    private javax.swing.JButton btn_ccontrasena;
    private javax.swing.JButton btn_regresar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbl_cau_ent;
    private javax.swing.JLabel lbl_cau_sal;
    private javax.swing.JLabel lbl_confirm;
    private javax.swing.JLabel lbl_identificador;
    private javax.swing.JLabel lbl_new_pwd;
    private javax.swing.JLabel lbl_nivel;
    private javax.swing.JLabel lbl_pH;
    private javax.persistence.EntityManager marengoPUEntityManager;
    private java.util.List<CapaDatos.Parametros> parametrosList;
    private javax.persistence.Query parametrosQuery;
    private javax.swing.JPasswordField pf_conf_contrasena;
    private javax.swing.JPasswordField pf_contrasena;
    private javax.swing.JPanel pnl_ccontrasena;
    private javax.swing.JPanel pnl_cparam;
    private javax.swing.JTextField tf_caudal_ent;
    private javax.swing.JTextField tf_caudal_salida;
    private javax.swing.JTextField tf_indentificador;
    private javax.swing.JTextField tf_nivel_tanque;
    private javax.swing.JTextField tf_pH;
    private javax.swing.JTabbedPane tpnl_opciones;
    // End of variables declaration//GEN-END:variables
}
